Exchange API
Request Access
In this section, we are explaining how to request API Access to a Rest API, creating a new application, and managing SLA Tiers.
Following in this article, there are some request examples that can be executed.
Before executing the examples, read the Anypoint Platform Token
section to know how to obtain the token to be used in the examples. This should be replaced for the value ANYPOINT_TOKEN
in each curl example.
The examples have been made by cURL, but optionally, instead of sending HTTP commands with cURL, you can use Postman or another application.
How to request API access
Note: this procedure is valid only for Rest APIs. Request API Group access will be eventually available in the Exchange API v2
Some URL parameters that have to be replaced in the examples are:
:organizationId
: Organization of the asset
:groupId
: Group ID of the asset
:assetId
: Asset ID of the asset
:version
: Version of the asset
The steps to Request API Access over a Rest API are:
1. First, a managed instance from the selected Rest API should be selected.
To do that, the asset should be retrieved from the Experience API to extract from there the needed instance:
curl 'https://anypoint.mulesoft.com/exchange/api/v1/assets/:groupId/:assetId/:version' \
-H 'Authorization: Bearer ANYPOINT_TOKEN'
A response like this will be retrieved.
The ID of an instance of “managed” type should be selected. In this example: "956703"
{
"groupId" : "5a673b98-92f4-459d-b950-daeed7a8165d",
"assetId" : "nuevisimo",
"type" : "rest-api",
"version" : "1.0.0",
"instances" : [
{
"id" : "956703",
"versionGroup" : "v1",
"name" : "v1:956703",
"environmentName" : "Sandbox",
"environmentId" : "fa07c403-3655-4e6b-8ea1-4888cc2775c1",
"type" : "managed",
"productAPIVersion" : "v1"
},
....
],
...
}
2. Select an existing Application or create a new one.
2.1. To create a new application:
Note: this procedure is valid only for non federated organizations
The instance ID selected in the step 1 should be used (956703
) as apiInstanceId
as URI parameter.
The application to be created has to have the following fields (they should be specified after the -d
):
name
: Name of the application
description
: Description of the application
url
: URL of the application
redirectUri
: An array of redirect Uris
grantTypes
: An array of Grant Types (example: "password", "implicit", "client_credentials", "authorization_code", "refresh_token")
apiEndpoints
: To automatically register the redirect URIs (it could take the values “true” or “false”)
curl 'https://anypoint.mulesoft.com/exchange/api/v1/organizations/:organizationId/applications?apiInstanceId=956703' \
-H 'accept: application/json' \
-H 'authorization: bearer ANYPOINT_TOKEN' \
-H 'content-type: application/json' \
-d '{"name":"new-application","description":"description","url":"http://app-url.com","redirectUri":["http://oauth-2.0-app-url.com"],"grantTypes":[],"apiEndpoints":false}'
A response like this will be retrieved.
The ID of the created application should be selected to be used in the next step. In this example it is: "273626"
{
"id":273626,
"redirectUri":["http://oauth-2.0-app-url.com"],
"name":"new-application",
"description":"description",
"url":"http://app-url.com",
"clientId":"2b9adc811b4842bfa614949ed2aa7b8c",
"clientSecret":"561C251D4C724E5ABE15D7c76d6C3E63",
"masterOrganizationId":"5a673b98-92f4-459d-b950-daeed7a8165d",
"grantTypes":[],
"clientProvider":{"providerId":null}
}
2.2. To get the applications that a user created on a specific master organization, execute the following example replacing the masterOrganizationId URI parameter:
curl 'https://anypoint.mulesoft.com/exchange/api/v1/organizations/:masterOrganizationId/applications' \
-H 'accept: application/json' \
-H 'authorization: bearer ANYPOINT_TOKEN'
A response like this will be retrieved.
The ID of an application should be selected. In this example: "273626"
[{
"id":273626,
"name":"new application for my rest-api",
"description":null,
"url":null,
"masterOrganizationId":"5a673b98-92f4-459d-b950-daeed7a8165d",
"clientProvider":{
"providerId":null
}
}, {
...
}]
3. Get the SLA Tiers of the selected managed instance.
If the API instance has Tiers, the user must select one SLA Tier. If the API instance has not Tiers, skip this step.
The SLA Tiers can be created in API Manager. For more information, visit https://docs.mulesoft.com/api-manager/2.x/api-sla-tiers.
An example of how to get the SLA Tiers of a managed instance is the following.
In this case, the instanceId should be replaced with 956703
, to be consistent with the entire example.
curl 'https://anypoint.mulesoft.com/exchange/api/v1/organizations/:organizationId/assets/:groupId/:assetId/productApiVersion/:apiVersion/instances/:instanceId/tiers' \
-H 'accept: application/json' \
-H 'authorization: bearer ANYPOINT_TOKEN'
A response like this will be retrieved.
The ID of an SLA Tier should be selected. In this example: 171457.
[{
"id":171457,
"name":"new SLA",
"description":null,
"limits":[{"timePeriodInMilliseconds":10000,"maximumRequests":1000}],
"status":"ACTIVE",
"autoApprove":true,
"applicationCount":0,
"apiId":956703
}, {
....
}]
4. Request access to creating a new contract.
The :applicationId
of the URL should be replaced by the created application ID 273463
, following the whole example.
The apiId
is the managed instance ID (for this case 956703
), and the requestedTierId
is the SLA Tier ID (for this case 171457
)
The fields required to request access that should be replaced in this example are (after the -d
tag):
apiId
: the managed instance ID
environmentId
: the application ID
requestedTierId
: the SLA Tier ID. (if none has been generated, just ignore it)
acceptedTerms
: true
to indicate the terms have been accepted
organizationId
: organizationId of the API asset to be requested access
groupId
: groupId of the API asset to be requested access
assetId
: assetId of the API asset to be requested access
version
: version of the API asset to be requested access
versionGroup
: versionGroup of the API asset to be requested access
curl 'https://anypoint.mulesoft.com/exchange/api/v1/organizations/:organizationId/applications/:applicationId/contracts' \
-H 'accept: application/json' \
-H 'authorization: bearer ANYPOINT_TOKEN' \
-H 'content-type: application/json' \
-d '{"apiId":"956703","environmentId":"fa07c403-3655-4e6b-8ea1-4888cc2775c1","requestedTierId":171457,"acceptedTerms":true,"organizationId":"5a673b98-92f4-459d-b950-daeed7a8165d","groupId":"5a673b98-92f4-459d-b950-daeed7a8165d","assetId":"asset-id","version":"1.0.0","versionGroup":"v1"}'
A response like this should be retrieved
{
"id":379427,
"status":"APPROVED",
"applicationId":273463,
"clientId":"a90a084a42fc455f8cd493fce5027dff",
"clientSecret":"cCab4Ed6278841469982c41f07bf9467",
"tier":{
"id":171457,
"name":"new SLA",
"description":null,
"limits":[{
"timePeriodInMilliseconds":10000,
"maximumRequests":1000
}],
"status":"ACTIVE",
"autoApprove":true
},
"api":{
"id":956703,
"version":"1.0.0",
"minorVersion":"1.0",
"organizationId":"5a673b98-92f4-459d-b950-daeed7a8165d",
"deprecated":false,
"groupId":"5a673b98-92f4-459d-b950-daeed7a8165d",
"assetId":"asset-id",
"assetVersion":"1.0.0",
"productVersion":"v1",
"environmentId":"fa07c403-3655-4e6b-8ea1-4888cc2775c1",
"fullname":"asset-id - Sandbox - undefined",
"assetName":"asset-id",
"environmentName":"Sandbox"
}
}
For more information about Client Applications and Request API Access:
https://docs.mulesoft.com/api-manager/2.x/api-contracts-landing-page